package org.com.Config;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

@Configuration
public class MetaConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
//        metaObject.setValue("createTime", LocalDateTime.now());
        if (metaObject.hasSetter("createTime")) {
            this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        }
//        metaObject.setValue("updateTime", LocalDateTime.now());

        if (metaObject.hasSetter("updateTime")) {
            this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        }

        if (metaObject.hasSetter("startTime")) {
            this.strictInsertFill(metaObject, "startTime", LocalDateTime.class, LocalDateTime.now());
        }
        if (metaObject.hasSetter("endTime")) {
            this.strictInsertFill(metaObject, "endTime", LocalDateTime.class, LocalDateTime.now());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasSetter("createTime")) {
            this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        }
        if (metaObject.hasSetter("updateTime")) {
            this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        }
//        metaObject.setValue("createTime", LocalDateTime.now());
//        metaObject.setValue("updateTime", LocalDateTime.now());
    }
}
